package com.kgc.sbt.exception;

import com.kgc.sbt.util.RequestResult;
import com.kgc.sbt.util.ResultBuildUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created on 2021/6/1.
 * <p>
 * Author: GongMingJie
 * <p>
 * Description: 自定义异常统一处理类
 */
@ControllerAdvice
@Slf4j
public class UserExceptionHandler {

    @ResponseBody
    @ExceptionHandler(UserException.class)
    public RequestResult<String> handUserException(UserException ee) {
        log.error("------ 获取系统的抛出的自定义异常，异常码：{},异常信息：{} -------", ee.getUserExceptionEnum().getExcptCode(), ee.getUserExceptionEnum().getExcptMsg());
        return ResultBuildUtil.fail(ee.getUserExceptionEnum().getExcptCode(), ee.getUserExceptionEnum().getExcptMsg());
    }
}
